package com.nbsaas.boot.example.data.entity;


import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "客户案例管理", model = "客户案例", menu = "1,57,64")
@Entity
@Table(name = "bs_example")
public class Example extends AbstractEntity {

    @SearchItem(label = "客户名称", name = "name")
    @FormField(title = "客户名称", sortNum = "2", grid = true, col = 18, required = true, width = "300")
    private String name;

    @Comment("案例图片")
    @FormField(title = "案例图片", sortNum = "2", type = InputType.image, col = 18)
    private String logo;

    @Comment("公司logo")
    @FormField(title = "公司logo", sortNum = "2", type = InputType.image, col = 18)
    private String companyLogo;

    @SearchItem(label = "案例分类", name = "exampleCatalog", key = "exampleCatalog.id", operator = Operator.eq, classType = Long.class, type = InputType.select)
    @FormField(title = "案例分类", sortNum = "2", type = InputType.select, grid = true, col = 18, option = "exampleCatalog")
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private ExampleCatalog exampleCatalog;

    @FormField(title = "介绍", sortNum = "2", col = 18)
    private String introduce;

    @Comment("是否在首页显示")
    @Dict(
            items = {
                    @DictItem(label = "否", value = 2),
                    @DictItem(label = "是", value = 1)
            }
    )
    private Integer showHome;


    @FormField(title = "排序号", sortNum = "2", col = 18, type = InputType.el_input_number, sort = true)
    private Integer sortNum;

    @FormField(title = "在线地址", sortNum = "2", col = 18)
    private String url;

    @FormField(title = "创建人", sortNum = "2", col = 18, grid = true, ignore = true)
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

    @FormField(title = "介绍", sortNum = "2", type = InputType.richText, col = 18)
    private String note;
}
